package com.fone.player.entity;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * 
 * 
 * 缓存碎片实体类，仅用于离线缓存下载使用，属于OfflineCache子集
 * 
 * @author wangyang
 * @since 2014年5月13日
 * 
 */
public class OfflineCacheFragment implements Parcelable {
	public static final String OFFLINE_CACHE_FRAGMENT = "offline_cache_fragment";
	public static final String OFFLINE_CACHE_FRAGMENT_LIST = "offline_cache_fragment_list";
	/**
	 * 标清
	 */
	public final static int CACHE_DEFINITION_STANDARD = 1;
	/**
	 * 高清
	 */
	public final static int CACHE_DEFINITION_HIGH = 2;
	/**
	 * 超清
	 */
	public final static int CACHE_DEFINITION_SUPER = 3;

	// 内容ID(第一层级)
	private long mCacheCID;
	// 内同集合ID(第二层级)
	private long mCacheCCID;
	// 节目名称
	private String mCacheName;
	// 节目已经缓存的大小
	private long mCacheAlreadySize;
	// 节目总大小
	private long mCacheTotalSize;
	// 节目缓存状态
	private int mCacheDownloadState;
	// 节目内容类型
	private int mCacheContentType;
	// 视频分片下载的URL
	private String mCacheFragmentUrl;
	// 视频分片下载URL的MD5值
	private String mCacheFragmentUrlMD5;
	// 节目地址(第一层级和第二层级点击缓存和全屏播放时使用,pt=1播放,pt=2下载)
	private String mCacheXYZPlayUrl;
	// 节目清晰度(1标清,2高清,3超清)
	private int mCacheDefinitionType;
	// 下载类型(1离线缓存,2图片,3apk,4边播边下)
	private int mCacheDownloadType = 1;
	// 总时长
	private long mCacheDuration;
	// 缓存分片视频路径
	private String mCacheFragmentStoragePath;
	// 记录当前节目在C层队列的索引,用于操作该节目下载
	private int mCacheCurrentIndex;
	// 分片下载时各自的出错代码
	private int mCacheFragmentErrorCode;

	@Override
	public void writeToParcel(Parcel out, int flags) {
		out.writeLong(mCacheCID);
		out.writeLong(mCacheCCID);
		out.writeString(mCacheName);
		out.writeLong(mCacheAlreadySize);
		out.writeLong(mCacheTotalSize);
		out.writeInt(mCacheDownloadState);
		out.writeInt(mCacheContentType);
		out.writeString(mCacheFragmentUrl);
		out.writeString(mCacheFragmentUrlMD5);
		out.writeString(mCacheXYZPlayUrl);
		out.writeInt(mCacheDefinitionType);
		out.writeInt(mCacheDownloadType);
		out.writeLong(mCacheDuration);
		out.writeString(mCacheFragmentStoragePath);
		out.writeInt(mCacheCurrentIndex);
		out.writeInt(mCacheFragmentErrorCode);
	}

	public static final Parcelable.Creator<OfflineCacheFragment> CREATOR = new Parcelable.Creator<OfflineCacheFragment>() {
		public OfflineCacheFragment createFromParcel(Parcel in) {
			return new OfflineCacheFragment(in);
		}

		public OfflineCacheFragment[] newArray(int size) {
			return new OfflineCacheFragment[size];
		}
	};

	private OfflineCacheFragment(Parcel in) {
		mCacheCID = in.readLong();
		mCacheCCID = in.readLong();
		mCacheName = in.readString();
		mCacheAlreadySize = in.readLong();
		mCacheTotalSize = in.readLong();
		mCacheDownloadState = in.readInt();
		mCacheContentType = in.readInt();
		mCacheFragmentUrl = in.readString();
		mCacheFragmentUrlMD5 = in.readString();
		mCacheXYZPlayUrl = in.readString();
		mCacheDefinitionType = in.readInt();
		mCacheDownloadType = in.readInt();
		mCacheDuration = in.readLong();
		mCacheFragmentStoragePath = in.readString();
		mCacheCurrentIndex = in.readInt();
		mCacheFragmentErrorCode = in.readInt();
	}

	public int getCacheFragmentErrorCode() {
		return mCacheFragmentErrorCode;
	}

	public void setCacheFragmentErrorCode(int cacheFragmentErrorCode) {

		mCacheFragmentErrorCode = cacheFragmentErrorCode;
	}

	public String getCacheFragmentUrl() {
		return mCacheFragmentUrl;
	}

	public void setCacheFragmentUrl(String cacheFragmentUrl) {
		mCacheFragmentUrl = cacheFragmentUrl;
	}

	public String getCacheFragmentUrlMD5() {
		return mCacheFragmentUrlMD5;
	}

	public void setCacheFragmentUrlMD5(String cacheFragmentUrlMD5) {
		mCacheFragmentUrlMD5 = cacheFragmentUrlMD5;
	}

	public int getCacheCurrentIndex() {
		return mCacheCurrentIndex;
	}

	public void setCacheCurrentIndex(int cacheCurrentIndex) {

		mCacheCurrentIndex = cacheCurrentIndex;
	}

	public int getCacheDefinitionType() {
		return mCacheDefinitionType;
	}

	public void setCacheDefinitionType(int cacheDefinitionType) {

		mCacheDefinitionType = cacheDefinitionType;
	}

	public int getCacheDownloadType() {
		return mCacheDownloadType;
	}

	public void setCacheDownloadType(int cacheDownloadType) {

		mCacheDownloadType = cacheDownloadType;
	}

	/**
	 * 
	 * 获取清晰度
	 * 
	 * 
	 * @return int 清晰度<br>
	 *         OfflineCache.CACHE_DEFINITION_STANDARD 标清<br>
	 *         OfflineCache.CACHE_DEFINITION_HIGH 高清<br>
	 *         OfflineCache.CACHE_DEFINITION_SUPER 超清<br>
	 */
	public long getCacheDuration() {
		return mCacheDuration;
	}

	/**
	 * 
	 * 设置清晰度
	 * 
	 * 
	 * @return int 清晰度<br>
	 *         OfflineCache.CACHE_DEFINITION_STANDARD 标清<br>
	 *         OfflineCache.CACHE_DEFINITION_HIGH 高清<br>
	 *         OfflineCache.CACHE_DEFINITION_SUPER 超清<br>
	 */
	public void setCacheDuration(long cacheDuration) {

		mCacheDuration = cacheDuration;
	}

	public String getCacheFragmentStoragePath() {
		return mCacheFragmentStoragePath;
	}

	public void setCacheFragmentStoragePath(
			String cacheFragmentVideoStoragePath) {

		mCacheFragmentStoragePath = cacheFragmentVideoStoragePath;
	}

	public long getCacheCID() {
		return mCacheCID;
	}

	public void setCacheCID(long cacheCID) {

		mCacheCID = cacheCID;
	}

	public long getCacheCCID() {
		return mCacheCCID;
	}

	public void setCacheCCID(long cacheCCID) {

		mCacheCCID = cacheCCID;
	}

	public String getCacheXYZPlayUrl() {
		return mCacheXYZPlayUrl == null ? "" : mCacheXYZPlayUrl;
	}

	public void setCacheXYZPlayUrl(String cacheXYZPlayUrl) {

		mCacheXYZPlayUrl = cacheXYZPlayUrl;
	}

	public String getCacheName() {
		return mCacheName == null ? "" : mCacheName;
	}

	public void setCacheName(String cacheName) {

		mCacheName = cacheName;
	}

	public long getCacheAlreadySize() {
		return mCacheAlreadySize;
	}

	public void setCacheAlreadySize(long cacheAlreadySize) {

		mCacheAlreadySize = cacheAlreadySize;
	}

	public void addCacheAlreadySize(long cacheAlreadySize) {

		mCacheAlreadySize += cacheAlreadySize;
	}

	public long getCacheTotalSize() {
		return mCacheTotalSize;
	}

	public void setCacheTotalSize(long cacheTotalSize) {

		mCacheTotalSize = cacheTotalSize;
	}

	/**
	 * 
	 * 返回百分比
	 * 
	 * @return int
	 */
	public int getCachePercentNum() {
		int percentNum = 0;
		if (mCacheTotalSize > 0) {
			percentNum = (int) (((double) mCacheAlreadySize / mCacheTotalSize) * 100);
		}
		return percentNum;
	}

	/**
	 * 
	 * 获取缓存状态
	 * 
	 * 
	 * @return int 缓存内容类型<br>
	 *         OfflineCache.CACHE_STATE_WAITING 等待<br>
	 *         OfflineCache.CACHE_STATE_PAUSE 暂停<br>
	 *         OfflineCache.CACHE_STATE_DOWNLOADING 下载中<br>
	 *         OfflineCache.CACHE_STATE_FINISH 完成<br>
	 *         OfflineCache.CACHE_STATE_ERROR 出错<br>
	 */
	public int getCacheDownloadState() {
		return mCacheDownloadState;
	}

	/**
	 * 
	 * 设置缓存状态
	 * 
	 * @param cacheState
	 *            缓存状态<br>
	 *            OfflineCache.CACHE_STATE_WAITING 等待<br>
	 *            OfflineCache.CACHE_STATE_PAUSE 暂停<br>
	 *            OfflineCache.CACHE_STATE_DOWNLOADING 下载中<br>
	 *            OfflineCache.CACHE_STATE_FINISH 完成<br>
	 *            OfflineCache.CACHE_STATE_ERROR 出错<br>
	 * @return void
	 */
	public void setCacheDownloadState(int cacheState) {

		mCacheDownloadState = cacheState;
	}

	/**
	 * 
	 * 获取缓存内容类型
	 * 
	 * 
	 * @return int 缓存内容类型<br>
	 *         来自服务器的favtyp字段
	 */
	public int getCacheContentType() {
		return mCacheContentType;
	}

	/**
	 * 
	 * 设置缓存内容类型
	 * 
	 * @param cacheContentType
	 *            缓存内容类型<br>
	 *            OfflineCache.CACHE_CONTENT_TYPE_ALL 全部<br>
	 *            OfflineCache.CACHE_CONTENT_TYPE_MOVIE 电影<br>
	 *            OfflineCache.CACHE_CONTENT_TYPE_TV 电视剧<br>
	 *            OfflineCache.CACHE_CONTENT_TYPE_ANIMATION 动漫<br>
	 *            OfflineCache.CACHE_CONTENT_TYPE_VARIETY 综艺<br>
	 *            OfflineCache.CACHE_CONTENT_TYPE_ORIGINAL 原创<br>
	 *            OfflineCache.CACHE_CONTENT_TYPE_LIVE_VIDEO 视频直播<br>
	 *            OfflineCache.CACHE_CONTENT_TYPE_LIVE_AUDIO 音频直播<br>
	 *            OfflineCache.CACHE_CONTENT_TYPE_NEWS 新闻<br>
	 *            OfflineCache.CACHE_CONTENT_TYPE_SHORT_FILM 短片<br>
	 *            OfflineCache.CACHE_CONTENT_TYPE_WEB_PAGE 网页<br>
	 * @return void
	 */
	public void setCacheContentType(int cacheContentType) {

		mCacheContentType = cacheContentType;
	}

	public OfflineCacheFragment() {

	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public String toString() {
		return "OfflineCacheFragment [mCacheName=" + mCacheName
				+ ", mCacheFragmentUrl=" + mCacheFragmentUrl
				+ ", mCacheDuration=" + mCacheDuration + "]";
	}

}
